/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.modules.repair.mapper;

import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
import org.apache.ibatis.annotations.Param;
import org.springblade.modules.repair.entity.MaintainMalfunctionRescue;
import org.springblade.modules.repair.entity.MaintainPlanContentUser;
import org.springblade.modules.repair.vo.*;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.modules.repair.vo.plan.PlanRescueDetailVO;
import org.springblade.modules.repair.vo.rescue.DispatcherPageReqVO;
import org.springblade.modules.repair.vo.rescue.DispatcherPageRespVO;
import org.springblade.modules.repair.vo.rescue.ElevatorOfRescueVo;

import java.util.Date;
import java.util.List;

/**
 * 救援工单明细 Mapper 接口
 *
 * @author ysq
 * @since 2023-02-25
 */
public interface MaintainMalfunctionRescueMapper extends BaseMapper<MaintainMalfunctionRescue> {

	/**
	 * 历史分页
	 *
	 * @param page
	 * @return
	 */
	List<MalfunctionRescueHistoryPageVO> selectMaintainMalfunctionRescueHistoryPage(IPage page,@Param("elevatorId") Long elevatorId);

    List<MalfunctionRescueHomeListVO> malfunctionRescueHomeList(@Param("userId") Long userId, @Param("startDate")Date startDate, @Param("endDate")Date endDate, @Param("sortByPlanDateASC")Boolean sortByPlanDateASC);

    MalfunctionRescueDetailVO malfunctionRescueDetail(@Param("planId") Long planId);

	List<RelevanceMalfunctionPlanVO> selectRelevanceMalfunctionPlan(@Param("planId") Long planId);

	/**
	 * 地图-救援人员详情
	 * @param planId
	 * @return
	 */
    List<MapUserInfoDetailVO> mapUserDetails(@Param("planId") Long planId);

	/**
	 * 救援详情
	 * @param planId
	 * @return
	 */
	@InterceptorIgnore(tenantLine = "on")
	RescueOrderDetail rescueDetail(@Param("planId") Long planId);

	/**
	 * 判断救援人员是否在出发中
	 * @param userId
	 * @return
	 */
	Boolean rescueUserRunning(@Param("userId") Long userId);

	/**
	 * 根据电梯id查找梯联网设备id
	 * @param elevatorId
	 * @return
	 */
	@InterceptorIgnore(tenantLine = "on")
	String getDeviceIdByElevatorId(@Param("elevatorId") Long elevatorId);

    MaintainPlanContentUser getTheFastUser(Long planId);


	/**
	 * 根据电梯获取救援任务
	 * @param type 1:查询进行中的，2：历史已经完成的
	 * @param elevatorId 电梯id
	 * @return 数据集
	 */
    List<ElevatorOfRescueVo> getElevatorOfRescueInfo(@Param("type")Integer type,@Param("elevatorId") Long elevatorId);

	/**
	 * 工单救援详情
	 * @param planId
	 * @return
	 */
	PlanRescueDetailVO getRescueDetail(@Param("planId") Long planId);

	/**
	 * 地图-救援人员信息
	 * @return
	 */
	List<MapUserInfoVO> mapUserList(@Param("screenRoles") String screenRoles, @Param("keyword") String keyword);


	/**
	 * 查询指定项目保养工单计划执行人
	 * @param buildingIds
	 * @return
	 */
	List<Long> selectBuildingRecentlyMaintainUser(@Param("buildingIds") List<Long> buildingIds);

	/**
	 * 调度分页
	 * @param dispatcherPageReqVO
	 * @param page
	 * @return
	 */
	IPage<DispatcherPageRespVO> dispatcherPage(@Param("reqParam") DispatcherPageReqVO dispatcherPageReqVO, IPage<DispatcherPageRespVO> page);

	/**
	 * 救援工单详情列表
	 * @param elevatorId
	 * @return
	 */
	List<RescueDetailVO> rescueDetailListByElevatorId(@Param("buildingId") Long buildingId, @Param("elevatorId") Long elevatorId);

	/**
	 * 判断是否有关联的维修单
	 * @param id
	 * @return
	 */
	Boolean hasRelaMalOrder(Long id);
}
